#!/bin/bash

_user="$(id 1000 -u -n)"

touch /etc/apt/apt.conf
cat << EOF > /etc/apt/apt.conf
APT::Install-Recommends "0";
Acquire::By-Hash "1";
Acquire::ForceIPv4 "1";
Acquire::Languages "0";
EOF

cat << EOF > /etc/apt/sources.list
deb https://deb.debian.org/debian/ buster main contrib non-free
deb https://deb.debian.org/debian/ buster-updates main contrib non-free
deb https://deb.debian.org/debian-security/ buster/updates main contrib non-free
deb https://deb.debian.org/debian/ buster-backports main contrib non-free
EOF

apt update

apt install -y alsa-utils aptitude bc bootcd breeze-cursor-theme btrfs-progs ca-certificates conky crda compton compton-conf curl dosfstools eject exfat-fuse exfat-utils f2fs-tools firmware-linux-nonfree flatpak flatpak-xdg-utils git gnome-themes-standard gnupg gparted gsimplecal gtk2-engines-murrine gtk2-engines-pixbuf gvfs gvfs-backends imagemagick jfsutils libgl1-mesa-dri libgl1-mesa-glx libglu1-mesa libnotify-bin lightdm lightdm-gtk-greeter-settings localepurge modemmanager mousepad nano network-manager-gnome ntfs-3g p7zip-full policykit-1-gnome python-gtk2 python-notify reiserfsprogs software-properties-common synaptic sysfsutils syslinux-utils tint2 thunar thunar-archive-plugin tumbler tumbler-plugins-extra ulatencyd unzip volumeicon-alsa wget wireless-regdb x11-xserver-utils xdotool xfce4-notifyd xfce4-screenshooter xfce4-session xfce4-settings xfce4-terminal xfdesktop4 xfonts-base xfsprogs xfwm4 xinit xserver-xorg xserver-xorg-core zip

flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo

rm /usr/share/applications/exo-mail-reader.desktop
rm /usr/share/applications/exo-terminal-emulator.desktop
rm /usr/share/applications/exo-web-browser.desktop
rm /usr/share/applications/Thunar-bulk-rename.desktop
rm /usr/share/applications/vim.desktop
rm /usr/share/applications/tint2.desktop
rm /usr/share/applications/Thunar.desktop
rm /usr/share/applications/display-im6.q16.desktop
rm /usr/share/applications/xfce4-session-logout.desktop
rm /usr/share/applications/xfce4-screenshooter.desktop
rm /usr/share/applications/compton.desktop

rm -r /usr/share/icons/Adwaita
rm -r /usr/share/themes/Adwaita
rm -r /usr/share/themes/Adwaita-dark
rm -r /usr/share/themes/Bright
rm -r /usr/share/themes/Daloa
rm -r /usr/share/themes/Emacs
rm -r /usr/share/themes/Kokodi
rm -r /usr/share/themes/Moheli
rm -r /usr/share/themes/Raleigh
rm -r /usr/share/themes/Retro
rm -r /usr/share/themes/Smoke
rm -r /usr/share/themes/ZOMG-PONIES!

wget --no-check-certificate https://dxt2.co.za/download/dxt23.7z
7z e dxt23.7z
7z x -aoa share.7z -o/usr/share
7z x -aoa skel.7z -o/etc/skel
7z x -aoa skel.7z -o/home/$_user
7z x -aoa skel.7z -o/root
rm *.7z
rm ./installdxt23

sed -i "s/#autologin-user=/autologin-user=$_user/g" /etc/lightdm/lightdm.conf
echo "export PATH=\"/usr/share/dxt2:\$PATH\"" >> /root/.bashrc

chown $_user:$_user -R /home/$_user
chown root:root -R /root
chown root:root -R /etc/skel

cat << EOF > /etc/sysctl.d/dxt2sysctl.conf
fs.file-max = 2097152
net.core.netdev_max_backlog = 65536
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.all.log_martians = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.icmp_ignore_bogus_error_messages = 1
net.ipv4.tcp_no_metrics_save = 1
net.ipv4.tcp_sack = 1
net.ipv4.tcp_timestamps = 0
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
vm.dirty_background_bytes = 16777216
vm.dirty_background_ratio = 2
vm.dirty_bytes = 50331648
vm.dirty_ratio = 50
vm.swappiness = 10
vm.vfs_cache_pressure = 50
EOF

cat << EOF > /etc/lightdm/lightdm-gtk-greeter.conf
[greeter]
background = /usr/share/backgrounds/debian.jpg
EOF

chsh -s /bin/bash root
chsh -s /bin/bash $_user

echo "%sudo    ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

find /usr/share/locale -mindepth 1 -maxdepth 1 ! -name 'en*' -exec rm -r {} \;
rm -r /usr/share/doc/*
rm -r /usr/share/help/*
rm -r /usr/share/i18n/*
rm -r /usr/share/man/*

/usr/share/dxt2/dxt2grub
/usr/share/dxt2/installtmp

amixer set Master 100%

sync
